#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<string.h>
#include<stdlib.h>

int g_val = 100;

int main()
{
  pid_t id = fork();
  if(id < 0){
    perror("fork error");
    return 1;
  }
  else if(id == 0){
    //child
    g_val = 200;
    printf("child pid: %d ppid: %d g_val: %d &g_val: %p\n", getpid(), getppid(), g_val, &g_val);
  }
  else{
    //parent
    sleep(2);
    printf("parent pid: %d ppid: %d g_val: %d &g_val: %p\n", getpid(), getppid(), g_val, &g_val);
  }
  sleep(1);
  return 0;
}
